package com.youlu.campus.web.jinshuju;


import com.youlu.campus.entity.VO.req.AuthNotifyReq;
import com.youlu.campus.entity.VO.res.AuthNotifyRes;
import com.youlu.campus.service.activity.ActivitySubscribeAppIdService;
import com.youlu.campus.service.jinshuju.JinShuJuActivityService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class JinActivityController {
    @Autowired
    private JinShuJuActivityService jinShuJuActivityService;
    @Autowired
    private ActivitySubscribeAppIdService activitySubscribeAppIdService;


    /**
     * 获取活动信息
     *
     * @param activityId
     * @return
     */
    @GetMapping("/public/jin/activity-info")
    public QResult activityInfo(String activityId) {
        return QResult.success(jinShuJuActivityService.findByActivityId(activityId));
    }

    /**
     * 获取活动信息的订阅的openId
     * 签到订阅
     *
     * @param req
     * @return
     */
    @PostMapping("/mini-app/activity/sub-info")
    public QResult getActivitySubInfo(@RequestBody AuthNotifyReq req) {
        AuthNotifyRes res = new AuthNotifyRes();
        res.setActivityId(req.getActivityId());
        res.setAppId(RequestContext.getAppId());
        res.setOpenId(RequestContext.getCurUser().getOpenId());
        return QResult.success(jinShuJuActivityService.getActivitySubInfo(req));
    }
}
